home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1998 July / EnigmA AMIGA RUN 29 (1998)(G.R. Edizioni)(IT)[!][issue 1998-07 & 08].iso / earkit / news / thor / rexx / bbsread / runcommand.br < prev    next >
Text File  |  1998-05-24  |  3KB  |  134 lines

  1. /*
  2. ** $VER: RunCommand.br 1.41 (13.5.97)
  3. **
  4. ** Intended for use as an SortMail external script, but can be used from the
  5. ** Shell as well.  Also servers as an example of how to create external
  6. ** scripts for SortMail.
  7. **
  8. ** See SortMail.guide for documentation
  9. **
  10. */
  11.  
  12. /*
  13. ** INITIALIZATION
  14. */
  15.  
  16. options results
  17.  
  18. signal on syntax
  19. signal on break_c
  20. signal on halt
  21.  
  22. options failat 30
  23.  
  24. parse arg arguments                      /* Get command line arguments */
  25.  
  26. template = 'COMMAND/A,OPTIONS/K,ASYNC/S' /* READARGS template */
  27.  
  28. /*
  29. ** Check if BBSREAD's ARexx port is open, open it if it's not
  30. */
  31.  
  32. if ~show('P', 'BBSREAD') then do
  33.     address(command)
  34.     'Run >NIL: `GetEnv THOR/THORPath`bin/LoadBBSRead'
  35.     if exists('SYS:RexxC/WaitForPort') then 'SYS:RexxC/WaitForPort BBSREAD'
  36.     else 'WaitForPort BBSREAD'
  37.     if (rc = 5) then do; say 'Could not open BBSREAD''s ARexx port.'; exit(30); end
  38.     if (rc ~= 0) then do; say 'Could not find SYS:Rexxc/WaitForPort.'; exit(30); end
  39.     end
  40.  
  41. /*
  42. ** Parse command line
  43. */
  44.  
  45. args.ASYNC = 0                         /* Switches are set to 0 so if tests can
  46.                                           be performed on them, like below */
  47. address(bbsread)
  48. 'READARGS TEMPLATE "'template'" STEM 'args' CMDLINE 'arguments
  49. if rc ~= 0 then do
  50.     say 'READARGS failed: 'BBSREAD.LASTERROR
  51.     say 'Template: 'template
  52.     say 'RunCommand.br is an external script for SortMail.'
  53.     exit(rc)
  54.     end
  55.  
  56. /*
  57. ** MAIN CODE - substitute with your own
  58. */
  59.  
  60. /*
  61. ** Create the command line
  62. */
  63.  
  64. if args.ASYNC then
  65.     cmdline = 'Run >NIL: "' || args.COMMAND || '" >T:RunCommand.out'
  66. else
  67.     cmdline = '"' || args.COMMAND || '" >T:RunCommand.out'
  68.  
  69. if symbol('args.OPTIONS') = 'VAR' then
  70.     cmdline = cmdline || ' ' || args.OPTIONS
  71.  
  72. /*
  73. ** Execute the command line
  74. */
  75.  
  76. address command cmdline
  77.  
  78. if rc ~= 0 then do
  79.     commandrc = rc
  80.     erropen = open(ef, 'T:RunCommand.out', 'R')
  81.     if erropen then do
  82.         say 'External script RunCommand.br failed: 'readln(ef)
  83.         call close(ef)
  84.         if exists('T:RunCommand.result') then
  85.             address command 'Delete "T:RunCommand.out" QUIET'
  86.         end
  87.     else
  88.         say 'External script RunCommand.br failed: Unknown error'
  89.     exit(commandrc)
  90.     end
  91.  
  92. /*
  93. ** Skip to cleanup: to do a clean exit
  94. */
  95.  
  96. signal cleanup
  97.  
  98.  
  99. /*
  100. ** ERROR HANDLING AND EXITING
  101. */
  102.  
  103. /*
  104. ** Error handling routine
  105. */
  106.  
  107. error:
  108. syntax:
  109.  
  110. /*
  111. ** Show BBSREAD, THOR or ARexx error
  112. */
  113.  
  114. select
  115.     when symbol('BBSREAD.LASTERROR') = 'VAR' then
  116.         say 'BBSREAD returned 'rc' in line 'sigl': 'BBSREAD.LASTERROR
  117.  
  118.     when symbol('THOR.LASTERROR')    = 'VAR' then
  119.         say 'THOR returned 'rc' in line 'sigl': 'THOR.LASTERROR
  120.  
  121.     otherwise say 'Error 'rc' in line 'sigl': 'errortext(rc)
  122.     end
  123.  
  124. /*
  125. ** Leave script, returning the proper error code (if any)
  126. */
  127.  
  128. cleanup:
  129. break_c:
  130. halt:
  131.  
  132. if symbol('rc') = 'VAR' then exit(rc)
  133. else exit(0)
  134.